package com.hos.punchtheclocksystem.config;

import com.hos.punchtheclocksystem.interceptor.SessionTimeoutInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Hanyixuan
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    SessionTimeoutInterceptor sessionTimeoutInterceptor;

    /**
     * 释放静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/assets/ckeditor/**").
                addResourceLocations("classpath:/static/assets/ckeditor/").
                setCachePeriod(2592000);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/card").setViewName("card");
        registry.addViewController("/list").setViewName("list");
        registry.addViewController("/cardAdd").setViewName("cardAdd");
        registry.addViewController("/patientAdd").setViewName("patientAdd");
        registry.addViewController("/cardEdit").setViewName("cardEdit");
        registry.addViewController("/patientEdit").setViewName("patientEdit");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionTimeoutInterceptor).addPathPatterns("/**").
                excludePathPatterns("/global","/list","/login","/static/**","/card","/doctor");
    }

}
